<?php

namespace App\Http\Controllers\Auto;

use App\Http\Controllers\Controller;
use App\Utils\ApiResponse;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;

class AutoOutServerController extends Controller
{
    use ApiResponse;

    /**
     * 浏览量自增
     * @return JsonResponse
     */
    public function viewInc(): JsonResponse
    {
        $hour = intval(date('H'));
        $inc = $hour > 12 ? 2 : 1;
        $sql = 'UPDATE document
SET views = views + CASE
    WHEN DATEDIFF(CURDATE(), datetime) <= 3 THEN ?
    WHEN DATEDIFF(CURDATE(), datetime) BETWEEN 4 AND 15 THEN ?
    ELSE ?
END WHERE datetime <= CURDATE() AND department = 1';
        DB::connection('rds_hb')->update($sql, [$inc, $inc - 1, $inc > 1 ? 1 : 0]);
        return $this->success();
    }

    private function getGradientDescentIncNumber()
    {

    }
}
